var app = getApp()
var wxParse = require("../../wxParse/wxParse.js")
Page({
  data: {
    showbtn:false,
    info:{},
    id:'',
    time:''
  },
  onShareAppMessage: function (res) {
    let member_id = app.globalData.userInfo.member_id
    return {
      title: '成纪先锋微平台',
      path: '/pages/study/tostudy?inviter_id=' + member_id,
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  onLoad: function (options) {
    let that = this
    if(options.from == 'rw'){
      if (options.id) {
        app.ajax("study_detail", { rd_session: wx.getStorageSync('rd_session'), id: options.id }, (data, err) => {
          this.setData({
            info: data.data,
            id: options.id,
            time: data.data.study_time
          })
          wxParse.wxParse("about", "html", data.data.content, this)
          setTimeout(function () {
            that.setData({
              showbtn: true
            })
          }, data.data.study_time * 60 * 1000)
        })
      }
    }else if(options.from == 'zl'){
      if (options.id) {
        app.ajax("study_detail", { rd_session: wx.getStorageSync('rd_session'), id: options.id }, (data, err) => {
          this.setData({
            info: data.data,
            id: options.id,
            time: data.data.study_time
          })
          wxParse.wxParse("about", "html", data.data.content, this)
        })
      }
    }
    
    
    
  },
  tostudy(){
    app.ajax("finish_study", { rd_session: wx.getStorageSync('rd_session'), id: this.data.id }, (data, err) => {
      if(data.result == 'success'){
        wx.switchTab({
          url: '/pages/mine/mine',
        })
      }
    })
  }

});